package num.c1;

import java.util.HashMap;

public class code_java_1 {

    class Solution {
        public int[] twoSum(int[] nums, int target) {

            // hash表储存 {nums[i], i}
            HashMap<Integer, Integer> hmap = new HashMap<>();

            for(int i = 0; i < nums.length; i++){
                if((!hmap.isEmpty()) && hmap.containsKey(target - nums[i])){
                    return new int[]{hmap.get(target - nums[i]), i};
                }
                hmap.put(nums[i], i);
            }

            return new int[0];

        }
    }
}
